package appium1.chapter1;


import io.appium.java_client.AppiumDriver;
import io.appium.java_client.android.AndroidDriver;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

import java.io.File;
import java.net.URL;

public class HelloWorld {
    private AppiumDriver driver;

    @BeforeMethod
    public void setUp() throws Exception {
        File app = new File(System.getProperty("user.dir"), "Aut/osc.apk");
        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability("platformName", "Android");
        capabilities.setCapability("deviceName", "Android Emulator");
        capabilities.setCapability("platformVersion", "7.1.2");
        capabilities.setCapability("app", app.getAbsolutePath());
        capabilities.setCapability("noReset", "True"); //每次不重新安装app
        capabilities.setCapability("appPackage", "net.oschina.app");
        capabilities.setCapability("resetKeyBoard","No");
        capabilities.setCapability("unicodeKeyboard","True");
        capabilities.setCapability("appActivity", ".improve.main.splash.SplashActivity");
        driver = new AndroidDriver<WebElement>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
    }

    @Test
    public void testName() throws Exception {
        Thread.sleep(5000);
        //  WebElement myTab1=driver.findElement(By.id("net.oschina.app:id/nav_item_me"));
        //  myTab1.click();
        //WebElement tab=(WebElement) driver.findElementsById("net.oschina.app:id/nav_tv_title").get(1);
        // System.out.print(tab.getText());
        //  tab.click();
        // WebElement tab2=(WebElement) driver.findElements(By.className("android.widget.TextView")).get(2);
        //tab2.click();
        WebElement tab = driver.findElement(By.xpath("//android.widget.TextView[@text='我的']"));
        tab.click();
        WebElement Myjq = driver.findElement(By.xpath("//android.widget.TextView[@text='我的问答']"));
        Myjq.click();
        WebElement Uername=driver.findElement(By.id("net.oschina.app:id/et_login_username"));
        Uername.sendKeys("你好啊");
        Thread.sleep(5000);
        //driver.findElementById("net.oschina.app:id/nav_item_me");
    }

    @AfterMethod
    public void tearDown() {
        try {
            Thread.sleep(8000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        driver.quit();
    }
}
